package com.plus.demo.service;

import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;

import org.mybatis.plus.annos.Transactional;
import org.springframework.stereotype.Service;

import com.plus.demo.mapper.AnswerMapper;
import com.plus.demo.mapper.UserMapper;
import com.plus.demo.po.Answer;
import com.plus.demo.po.User;
@Service
public class BizService {
	@Resource
	private UserMapper userMapper;
	@Resource
	private AnswerMapper answerMapper;
	
	@Transactional
	public void save() {
		User user = new User();
		user.setUserId(1);
		user.setUserName("springboot");
		user.setPassword("8284848448");
		user.setPhone("8388448844848");
		userMapper.save(user);
		Answer record = new Answer();
		record.setChoiceId(11);
		record.setEnabled(true);
		record.setQuestionnaireId(22);
		record.setUserId(11);
		record.setVersion(0);
		record.setCreateTime(new Date());
		record.setUpdateTime(new Date());
	    answerMapper.insert(record);
	    //System.out.println(1/0);
	}
	
	@Transactional
	public void save2() {
		User user = new User();
		user.setUserId(1);
		user.setUserName("springboot");
		user.setPassword("8284848448");
		user.setPhone("8388448844848");
		userMapper.save(user);
	}
	
	@Transactional
	public List<User>  saveAndQuery() {
		User user = new User();
		user.setUserId(1);
		user.setUserName("springboot");
		user.setPassword("8284848448");
		user.setPhone("8388448844848");
		userMapper.save(user);
		return this.query();
	}

	private List<User> query() {
		return userMapper.queryCondition5(new HashMap<String, Object>() {
			private static final long serialVersionUID = 1L;
			{
				put("userName", "springboot");
			}
		});
	}
}
